import 'package:get/get.dart';
import 'package:ball_lion/entity/match/hot_league_list_entity.dart';
import 'package:ball_lion/server/api/basketball_api.dart';
import 'package:ball_lion/server/api/soccer_api.dart';
import 'package:ball_lion/utils/sp_utils.dart';

class MatchService extends GetxService {
  //一级 热门
  HotLeagueListEntity? zqOneLevelLeague;
  HotLeagueListEntity? lqOneLevelLeague;
  List<int> zqOneLevelId = [];
  List<int> lqOneLevelId = [];
  List<int> zqHotId = [];
  List<int> lqHotId = [];

  Future<MatchService> init() async {
    getZqOneLevelLeague();
    getLqOneLevelLeague();
    return this;
  }

  getZqOneLevelLeague() async {
    if (SpUtils.matchOneLevelKey != null) {
      zqOneLevelLeague =
          HotLeagueListEntity.fromJson(SpUtils.matchOneLevelKey!);
    }
    final result = await SoccerApi.getZqHotLeague();
    if (result != null) {
      zqOneLevelLeague = result;
      SpUtils.matchOneLevelKey = result.toJson();
    }
    zqOneLevelId =
        zqOneLevelLeague!.level1List!.map((e) => e.leagueId!).toList();
    zqHotId = zqOneLevelLeague!.hotList!.map((e) => e.leagueId!).toList();
  }

  getLqOneLevelLeague() async {
    if (SpUtils.basketOneLevelKey != null) {
      lqOneLevelLeague =
          HotLeagueListEntity.fromJson(SpUtils.basketOneLevelKey!);
    }
    final result = await BasketballApi.getHotLqLeagueList();
    if (result != null) {
      lqOneLevelLeague = result;

      SpUtils.basketOneLevelKey = result.toJson();
    }
    lqOneLevelId =
        lqOneLevelLeague!.level1List!.map((e) => e.leagueId!).toList();
    lqHotId = lqOneLevelLeague!.hotList!.map((e) => e.leagueId!).toList();
  }
}
